<template>
    <div>
        <van-field label="名称" placeholder="请输入名称" v-model="form.name"/>
        <br>
        图片上传
        <van-uploader :after-read="afterRead" />
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form:{},
                pic:'http://localhost:5000/static/upload/',
            }
        },
        methods:{
            //图片上传
            afterRead(file){
                //只要是上传文件就需要声明formdata
                let data=new FormData()
                //将文件封装到data里
                data.append('file',file.file)
                this.$axios.post('addpic',data).then(res=>{
                    //更新图片 图片地址                              图片名
                    this.pic='http://localhost:5000/static/upload/'+res.data.pic
                })
            }
        },
        mounted(){},
    }
</script>

<style scoped>

</style>